package com.jlcloud.sequence;

import org.springframework.util.StringUtils;

/**
 * <p>默认生成器</p>
 *
 * @author By: zhangchunyang <br>
 * @Package: com.jlcloud.sequence <br>
 * @CreateTime: 2024-12-05 15:26 <br>
 * @Copyright: 2021 www.jilianjituan.com Inc. All rights reserved. <br>
 * @Caution 注意：本内容仅限于冀联人力集团内部传阅，禁止外泄以及用于其他的商业目的 <br>
 */
public class JlCloudIdentifierGenerator {

	private final Sequence sequence;

	public JlCloudIdentifierGenerator() {
		this.sequence = new Sequence();
	}

	public JlCloudIdentifierGenerator(long workerId, long dataCenterId) {
		this.sequence = new Sequence(workerId, dataCenterId);
	}

	public JlCloudIdentifierGenerator(Sequence sequence) {
		this.sequence = sequence;
	}

	/**
	 * 获取序列号号
	 *
	 * @return
	 */
	public Long nextId() {
		return sequence.nextId();
	}

	/**
	 * 获取序列号号
	 *
	 * @return
	 */
	public String nextIdString() {
		return nextIdString(null);
	}

	/**
	 * 获取序列号号
	 *
	 * @param prefix 序列号前缀
	 * @return
	 */
	public String nextIdString(String prefix) {
		if (!StringUtils.isEmpty(prefix)) {
			return prefix + sequence.nextId();
		} else {
			return String.valueOf(sequence.nextId());
		}
	}

//	public static void main(String[] args) {
//		JobslinkIdentifierGenerator next = new JobslinkIdentifierGenerator();
//		System.out.println( next.nextIdString());
//		System.out.println( next.nextId());
//	}
}
